# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=rfc3986-validator
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.1.1
pkgrel=5
pkgdesc="Pure python rfc3986 validator (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/naimetti/rfc3986-validator'
msys2_references=(
  'purl: pkg:pypi/rfc3986-validator'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-pytest"
  "${MINGW_PACKAGE_PREFIX}-python-rfc3987"
  "${MINGW_PACKAGE_PREFIX}-python-hypothesis"
)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname/-/_}-${pkgver}.tar.gz"
        "0001-remove-pytest-runner-dep.patch")
sha256sums=('3d44bde7921b3b9ec3ae4e3adca370438eccebc676456449b145d533b240d055'
            '993bd678996e98fad8912416b94e773c257d17f68b5e39794c84428db21ba9d3')

prepare() {
  cd "${_realname/-/_}-${pkgver}"
  patch -Np1 -i ../0001-remove-pytest-runner-dep.patch
}

build() {
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/python -m pytest
}

package() {
  cd "${srcdir}"/python-build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
